package com.frxuexi.adapter

import android.widget.TextView
import androidx.core.view.setMargins
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.GlideUtil
import com.frxuexi.lib_base.entity.MyHourse
import com.frxuexi.soufang.R
import com.google.android.flexbox.FlexboxLayout
import com.google.android.flexbox.FlexboxLayout.LayoutParams

class OldHourseAdapter:BaseQuickAdapter<MyHourse,BaseViewHolder>(R.layout.item_oldhourse) {
    override fun convert(helper: BaseViewHolder, item: MyHourse) {
        GlideUtil.loadImg(item.indexPictureUrl,helper.getView(R.id.old_iv))
        helper.setText(R.id.old_title,item.title)
        helper.setText(R.id.old_desc,
            "${item.garden.region.parent.name}/${item.garden.region.name}/${item.bedRoom}室${item.livingRoom}厅/${item.area}平")
        helper.setText(R.id.old_price,"${item.price/10000}.${item.price%10000}万")
        helper.setText(R.id.old_pricePer,item.moreDetails.get(0).content)

        val flex = helper.getView<FlexboxLayout>(R.id.old_flex)
        flex.removeAllViews()
        item.labelDesc?.split("|")?.forEach {
            val tv = TextView(context)
            tv.apply {
                setText(it)
                setBackgroundResource(R.drawable.shape_back)
                setPadding(20,5,20,5)
                layoutParams=LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT).apply {
                    setMargins(10)
                }
            }
            flex.addView(tv)
        }


    }
}